package com.honry.identityaccess.domain.model.identity;

import com.honry.common.domain.model.ConcurrencySafeEntity;
import com.honry.common.domain.model.DomainEventPublisher;

public class Person extends ConcurrencySafeEntity {

	private static final long serialVersionUID = 1L;
	private ContactInfo contactInfo;
	private String name;
	private User user;
	public Person() {
		super();
	}
	public Person(String name,ContactInfo contactInfo) {
		this.setName(name);
		this.setContactInfo(contactInfo);
	}
	public void PersonContactInfoChanged(ContactInfo contactInfo){
		this.contactInfo=contactInfo;
		DomainEventPublisher.instance().
		publish(new PersonContactInfoChanged(
						this.contactInfo, 
						this.user.username()));
	}
	/**
	 * 姓名
	 * @return
	 */
	public String name(){
		return this.name;
	}
	protected void setName(String name) {
        this.assertArgumentNotNull(name, "人员姓名为必填项.");

        this.name = name;
    }
	protected User user() {
        return this.user;
    }

    public void internalOnlySetUser(User aUser) {
        this.user = aUser;
    }
    @Override
    public boolean equals(Object anObject) {
        boolean equalObjects = false;

        if (anObject != null && this.getClass() == anObject.getClass()) {
            Person typedObject = (Person) anObject;
            equalObjects =
                    
                    this.user().username().equals(typedObject.user().username());
        }

        return equalObjects;
    }

    @Override
    public int hashCode() {
        int hashCodeValue =
            + (90113 * 223)
            
            + this.user().username().hashCode();

        return hashCodeValue;
    }

    @Override
    public String toString() {
        return "Person [ name=" + name +  "]";
    }
	public ContactInfo contactInfo() {
		return contactInfo;
	}
	private void setContactInfo(ContactInfo contactInfo) {
		this.assertArgumentNotNull(contactInfo, "人员联系信息不能为空.");
		this.contactInfo = contactInfo;
	}
}
